typedef struct	_TIMER
{
	DWORD	TimeOutVal;
	BOOL	IsTimeOut;								
} TIMER;

DWORD gSysTick;

void Timer0(void) interrupt 1	using 1				
{
	TR0 = 0; 
	TL0 = ((BYTE*)&gTimer0Count)[1];
	TH0 = ((BYTE*)&gTimer0Count)[0];
	TR0 = 1; 

 	if(!++(*((BYTE*)(&gSysTick) + 3)))    
 	{
  		if(!++(*((BYTE*)(&gSysTick) + 2)))
  		{
   			if(!++(*((BYTE*)(&gSysTick) + 1)))
   			{
     			(*((BYTE*)(&gSysTick) + 0))++;
   			}
  		}
 	}
}

VOID TimeOutSet(TIMER *timer, DWORD timeout)
{
	timer->TimeOutVal = gSysTick + timeout;		
	timer->IsTimeOut = FALSE;				
}

BOOL IsTimeOut(TIMER *time)
{
	if(!timer->IsTimeOut)
	{
		if((SDWORD)(gSysTick - timer->TimeOutVal) > 0)
		{
			timer->IsTimeOut = TRUE;
		}
	}	
	return timer->IsTimeOut;					
}